/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SysAguas.controle;

import SysAguas.dao.DAOHospede;
import SysAguas.modelo.Hospede;
import SysAguas.visao.PanelCadastrarReserva;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;
import javax.swing.DefaultListSelectionModel;
import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 *
 * @author Heitor
 */
public class TableHospedeReserva implements ListSelectionListener, MouseListener {

    private PanelCadastrarReserva panelCadastrarReserva = null;

    public TableHospedeReserva(PanelCadastrarReserva panel) {
        panelCadastrarReserva = panel;
    }

    public void valueChanged(ListSelectionEvent e) {
        System.out.println(" Test table" + e.toString());
        DefaultListSelectionModel a = (DefaultListSelectionModel) e.getSource();


    }

    public void mouseClicked(MouseEvent e) {
        if (e.getSource() == panelCadastrarReserva.getJtable2()) {
            Hospede hos = new Hospede();
            List<Hospede> lista = null;

            DAOHospede dao = new DAOHospede();


            String nome = (String) panelCadastrarReserva.getJtable2().getValueAt(
                    panelCadastrarReserva.getJtable2().getSelectedRow(), 0);
            String sobrenome = (String) panelCadastrarReserva.getJtable2().getValueAt(
                    panelCadastrarReserva.getJtable2().getSelectedRow(), 1);

            lista = dao.getHospedeByName(nome, sobrenome);
            hos = lista.get(0);

            panelCadastrarReserva.getNome_Cadastro().setText(hos.getNome());
            panelCadastrarReserva.getSobrenome_Cadastro().setText(hos.getSobrenome());

            if (hos.getTelefones().size() == 2) {
                String dddT = hos.getTelefones().get(0).getDdd();
                String numeroT = hos.getTelefones().get(0).getNumero();
                panelCadastrarReserva.getTelefone_Cadastro().setText("(" + dddT + ")" + numeroT);

                String dddC = hos.getTelefones().get(1).getDdd();
                String numeroC = hos.getTelefones().get(1).getNumero();
                panelCadastrarReserva.getCelular_cadastro().setText("(" + dddC + ")" + numeroC);
            }
            if (hos.getTelefones().size() == 1) {
                String dddT = hos.getTelefones().get(0).getDdd();
                String numeroT = hos.getTelefones().get(0).getNumero();
                panelCadastrarReserva.getTelefone_Cadastro().setText("(" + dddT + ")" + numeroT);
            }
        }
    }

    public void mousePressed(MouseEvent e) {
    }

    public void mouseReleased(MouseEvent e) {
    }

    public void mouseEntered(MouseEvent e) {
    }

    public void mouseExited(MouseEvent e) {
    }
}
